package com.useeinfo.oa.modules.wuHanCommon.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.func.excel.annotation.ExcelField;
import com.useeinfo.framework.sugar.func.excel.annotation.ExcelFields;
import com.useeinfo.framework.sugar.tools.CommonSugar;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.oa.modules.base.entity.Facility;
import com.useeinfo.oa.modules.wuHanCommon.base.enums.PointSystem;

import javax.persistence.*;
import javax.validation.Valid;

/**
 * 点位表
 */
@Entity
@Table(name = "wuhan_point")
public class WuHanPoint extends SuperClassEntity<WuHanPoint> {

    /**
     * 点位名称
     */
    private String name;
    /**
     * 备注
     */
    private String remark;
    /**
     * 单位
     */
    private String unitOfMeasurement;
    /**
     * 所属设备
     */
    @ManyToOne
    @JoinColumn(name = "unit_id")
    private WuHanUnit wuHanUnit;
    /**
     * 等级
     */
    private String lvl;

    @Transient
    private String unit;
    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        WuHanUnit wuHanUnit = CommonSugar.getTypedDefault(getWuHanUnit(), new WuHanUnit());
        jsonObject.put("pointId", CommonSugar.getTypedDefault(getId(), 0L));
        jsonObject.put("name", CommonSugar.getTypedDefault(getName(), ""));
        jsonObject.put("remark", CommonSugar.getTypedDefault(getRemark(), ""));
        jsonObject.put("unit", CommonSugar.getTypedDefault(wuHanUnit.getUnit(), ""));
        jsonObject.put("unitOfMeasurement", CommonSugar.getTypedDefault(getUnitOfMeasurement(), ""));
        jsonObject.put("meterReadingName", wuHanUnit.getMeterReadingEnum() == null ? "" : wuHanUnit.getMeterReadingEnum().getName());
        jsonObject.put("pointSystemName", wuHanUnit.getPointSystem() == null ? "" : wuHanUnit.getPointSystem().getName());

        return jsonObject;
    }

    @Valid
    @ExcelFields({
            @ExcelField(title = "点位", attrName = "name", align = ExcelField.Align.CENTER, sort = 30),
            @ExcelField(title = "备注", attrName = "remark", align = ExcelField.Align.CENTER, sort = 30),
            @ExcelField(title = "设备", attrName = "unit", align = ExcelField.Align.CENTER, sort = 30),
            @ExcelField(title = "单位", attrName = "unitOfMeasurement", align = ExcelField.Align.CENTER, sort = 30),
    })

    /*导入导出列子
    @Valid
    @ExcelFields({
            @ExcelField(title="归属机构", attrName="employee.office", align=Align.CENTER, sort=10, fieldType=OfficeType.class),
            @ExcelField(title="归属公司", attrName="employee.company", align = Align.CENTER, sort=20, fieldType=CompanyType.class),
            @ExcelField(title="登录账号", attrName="loginCode", align=Align.CENTER, sort=30),
            @ExcelField(title="用户昵称", attrName="userName", align=Align.CENTER, sort=40),
            @ExcelField(title="电子邮箱", attrName="email", align=Align.LEFT, sort=50),
            @ExcelField(title="手机号码", attrName="mobile", align=Align.CENTER, sort=60),
            @ExcelField(title="办公电话", attrName="phone", align=Align.CENTER, sort=70),
            @ExcelField(title="员工编码", attrName="employee.empCode", align=Align.CENTER, sort=80),
            @ExcelField(title="员工姓名", attrName="employee.empName", align=Align.CENTER, sort=95),
            @ExcelField(title="拥有角色编号", attrName="userRoleString", align=Align.LEFT, sort=800, type=ExcelField.Type.IMPORT),
            @ExcelField(title="最后登录日期", attrName="lastLoginDate", align=Align.CENTER, sort=900, type=ExcelField.Type.EXPORT, dataFormat="yyyy-MM-dd HH:mm"),
    })*/

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public WuHanUnit getWuHanUnit() {
        return wuHanUnit;
    }

    public void setWuHanUnit(WuHanUnit wuHanUnit) {
        this.wuHanUnit = wuHanUnit;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getUnitOfMeasurement() {
        return unitOfMeasurement;
    }

    public void setUnitOfMeasurement(String unitOfMeasurement) {
        this.unitOfMeasurement = unitOfMeasurement;
    }

    public String getLvl() {
        return lvl;
    }

    public void setLvl(String lvl) {
        this.lvl = lvl;
    }
}
